package org.springleaf.utils;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
 * 类工具
 * @author leaf
 *
 */
@SuppressWarnings("rawtypes")
public class ClassUtils {
	
	/**
	 * 当前类的泛型类型
	 */
	public static Class getGeneric(Object obj){
		Type type = (Type) obj.getClass().getGenericSuperclass();
		ParameterizedType pt = (ParameterizedType) type;
		Class classz = ((Class) pt.getActualTypeArguments()[0]);
		return classz;
	}
	
	/**
	 * 得到指定对象的beanname(默认为类名首字母小写)
	 * @param obj
	 */
	public static String getSimpleBeanName(Object obj){
		String name;
		if(obj instanceof Class){
			name = ((Class)obj).getSimpleName();
		}else{
			name = obj.getClass().getSimpleName();
		}
		return name.substring(0,1).toLowerCase() + name.substring(1);
	}
}
